/**
 * chenuu.com
 * 
 * @author  zhaoxu.com@gmail.com
 * @created 2012-11-3
 */
package com.chenuu.integration.httpclient.utils;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.chenuu.integration.httpclient.RequestParameter;

/**
 *
 */
public class OAuthUtil {

	public static String generateSignatureBaseString(String requestMethod, String requestTokenUrl,
			List<RequestParameter> params) {

		String signatureBaseString = requestMethod + "&" + RequestUtil.encode(requestTokenUrl);

		if (params != null) {
			Collections.sort(params);
			String paramString = "";
			boolean isFirst = true;
			for (RequestParameter param : params) {
				if (isFirst) {
					isFirst = false;
				} else {
					paramString += "&";
				}
				paramString += param;
			}
			signatureBaseString += "&" + RequestUtil.encode(paramString);
		}

		return signatureBaseString;
	}

	public static String generateTimestamp() {
		return (new Date().getTime() + "").substring(0, 10);
	}

	public static String generateNonce() {
		return new Date().getTime() + "";
	}
}
